package com.bynk.bynk_demo.common.result;

public class Result <T>{
    private String code;

    private String message;

    private T data;

    // 请求成功，指定data
    public static <T> Result<T> success(T data) {
        return new Result<>(ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }

    // 请求成功，指定data和指定message
    public static <T> Result<T> success(String message, T data) {
        return new Result<>(ResultEnum.SUCCESS.getCode(), message, data);
    }

    // 请求失败
    public static Result<?> failed() {
        return new Result<>(ResultEnum.UNVALID.getCode(), ResultEnum.UNVALID.getMessage(), null);
    }

    // 请求失败，指定message
    public static Result<?> failed(String message) {
        return new Result<>(ResultEnum.UNAUTH_POST.getCode(), message, null);
    }

    // 请求失败，指定code和message
    public static Result<?> failed(String code, String message) {
        return new Result<>(code, message, null);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }



    public Result() {
    }

    public Result(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
